package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.Member;
import cn.anxingongyou.anxin.mapper.MemberMapper;
import cn.anxingongyou.anxin.service.MemberService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {

    private final MemberMapper memberMapper;
    @Autowired
    public MemberServiceImpl(MemberMapper memberMapper) {
        this.memberMapper = memberMapper;
    }

    @Override
    public int insert(Member member) {
        return memberMapper.insertSelective(member);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return memberMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Member member) {
        return memberMapper.updateByPrimaryKeySelective(member);
    }

    @Override
    public Member selectOne(Member member) {
        return memberMapper.selectOne(member);
    }

    @Override
    public Member selectOneByPrimaryKey(Long id) {
        return memberMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Member> selectAll() {
        return memberMapper.selectAll();
    }

    @Override
    public PageInfo<Member> page(int pageNum, int pageSize, Member member) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<Member> list = memberMapper.select(member);
        PageInfo<Member> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
